package com.fare.taluo.fetl.domain.base;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.fare.taluo.base.ddd.domain.IBaseEntity;
import com.fare.taluo.base.ddd.repository.EntityHibernateRepository;

@Repository("entityFetlHibernateRepository")
public class EntityFetlHibernateRepository extends EntityHibernateRepository {
	
	@Autowired
	private SessionFactory sessionFactory1;

	public SessionFactory getSessionFactory1() {
		return sessionFactory1;
	}
	public void setSessionFactory1(SessionFactory sessionFactory1) {
		this.sessionFactory1 = sessionFactory1;
	}
	@SuppressWarnings("unchecked")
	@Override
	@Transactional(value="txManager1")
	public <T extends IBaseEntity> T get(Class<T> clazz, Serializable id) {
		return (T) sessionFactory1.getCurrentSession().get(clazz, id);
	}
	@SuppressWarnings("unchecked")
	@Override
	@Transactional(value="txManager1")
	public <T extends IBaseEntity> T find(Class<T> clazz, Serializable id) {
		return (T) sessionFactory1.getCurrentSession().load(clazz, id);
	}
	@Override
	@Transactional(value="txManager1")
	public <T extends IBaseEntity> boolean exists(Class<T> clazz, Serializable id) {
		return get(clazz, id) != null;
	}
	@Override
	@Transactional(value="txManager1")
	public <T extends IBaseEntity> List<T> findAll(Class<T> clazz) {
		Criteria criteria=sessionFactory1.getCurrentSession().createCriteria(clazz);
		return criteria.list(); 
	}

	@Override
	public <T extends IBaseEntity> void create(T o) {
		logger.error("不支持的方法!");
	}
	@Override
	public <T extends IBaseEntity> void update(T o) {
		logger.error("不支持的方法!");
	}
	@Override
	public <T extends IBaseEntity> void delete(Class<T> clazz, Serializable id) {
		logger.error("不支持的方法!");
	}
	@Override
	public <T extends IBaseEntity> void delete(T o) {
		logger.error("不支持的方法!");
	}
	@Override
	public <T extends IBaseEntity> void save(T o) {
		logger.error("不支持的方法!");
	}
}
